package day230916;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

/**
 * @author 兴趣使然黄小黄
 * @version 1.0
 * @date 2023/9/16 18:14
 * 字符串消除 100%
 */
public class Solution01 {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextLine()) {
            String input = in.nextLine();
            // 边界
            if (input == null || input.length() < 3) {
                System.out.println(input);
                continue;
            }
            // 利用栈来辅助消除
            Deque<Character> stack = new ArrayDeque<>();
            char[] s = input.toCharArray();
            int n = s.length;
            // 迭代消除
            int index = 0;
            while (index < n) {
                // 如果栈中的元素不足两个
                if (stack.size() < 2) {
                    stack.push(s[index++]);
                    continue;
                }
                // 从栈中取出, 比对是否消除
                char popVal = stack.pop();
                if (popVal == stack.peek() && popVal == s[index]) {
                    // 符合消除的条件
                    stack.pop();
                } else {
                    // 不符合消除的条件
                    stack.push(popVal);
                    stack.push(s[index]);
                }
                index++;
            }
            // 此时只剩下未消除的字符串
            StringBuilder res = new StringBuilder();
            while (!stack.isEmpty()) {
                res.append(stack.pop());
            }
            System.out.println(res.reverse());
        }
        in.close();
    }
}
